package flexo.scene;

public abstract class ExclusiveEntity extends Entity
{
	protected Node exclusiveNode;

	public ExclusiveEntity(Type type)
	{
		super(type);
	}
	
	public boolean isAttached()
	{
		return this.exclusiveNode != null;
	}
	
	@Override
	public boolean attachTo(Node n)
	{
		boolean result = super.attachTo(n);
		if (result && exclusiveNode != null)
		{
			deattachFrom(exclusiveNode);
		}
		exclusiveNode = n;
		return result;
	}
	
	public void deattach()
	{
		deattachFrom(this.exclusiveNode);
	}
	
	@Override
	public void deattachFrom(Node n)
	{
		super.deattachFrom(n);
		if (n == exclusiveNode)
		{
			exclusiveNode = null;
		}
	}
}
